//app.js
App({
  rootUrl:"https://www.myfoxcloud.com/",
  cart:{},//购物车
  cartSummary:{},//购物车总价格 总数量 用于订单显示
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  onShow: function(){
    console.log('onShow');
  },
  onHide: function(){
    console.log('onHide');
  },
  getUserInfo:function(cb){
    var that = this;
    if(this.globalData.userInfo){
      console.log('abc');
      typeof cb == "function" && cb(this.globalData.userInfo);
      console.log(cb);
    }else{
      //调用登录接口
      wx.login({
        success: function (res) {
          if(res.code){
            wx.request({
              url:"https://www.myfoxcloud.com/api/login",
              data:{code:res.code},
              success:function(responseData){
                  console.log(responseData);
              }
            });
          }
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo;
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      });
    }
  },
  globalData:{
    userInfo:null
  }
})
